#include "prostartup_newpro.h"
#include "ui_prostartup_newpro.h"

#include <QDebug>

proStartup_newPro::proStartup_newPro(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::proStartup_newPro)
{
    ui->setupUi(this);

    Qt::WindowFlags winFlag = Qt::Dialog;
    winFlag |= Qt::WindowCloseButtonHint;

    setWindowFlags(winFlag);  // 设置右上角窗口按钮

    this->proTree = "/";
}

proStartup_newPro::~proStartup_newPro()
{
    delete ui;
}

void proStartup_newPro::on_pushButton_cansel_clicked()
{
    this->close();
}


void proStartup_newPro::on_pushButton_finish_clicked()
{
    Project_Path proPath;

    if (ui->lineEdit_proName->text().isEmpty())
    {
        ui->lineEdit_proName->setStyleSheet("QLineEdit{border: 2px solid red}");
        return;
    }

    proPath.proName = ui->lineEdit_proName->text() + PROJECT_FILE_END_FORMAT;
    proPath.proFilePath = this->getProjectPath(ui->lineEdit_proFilePath->text());

    emit sendProjectPath(proPath);
    this->close();
}

void proStartup_newPro::set_proNewFilePath(QString path)
{
    qDebug() << path;
    this->proFilePath = path;

    ui->lineEdit_proFilePath->setText(path);
}

void proStartup_newPro::set_rootTreeItem(QTreeWidgetItem *root)
{
    this->root = root;

    this->proStoreFolderpath = project_startup_interface::get_proStoreFolderPath(root);

    ProStoreFolderPath::iterator test = this->proStoreFolderpath.begin();

//    while (test != this->proStoreFolderpath.end()) {
//        ;;
//    }
}


void proStartup_newPro::on_lineEdit_proName_textChanged(const QString &arg1)
{
//    ui->lineEdit_proName->setStyleSheet("");

    if (arg1.isNull() || arg1.isEmpty())
    {
//        ui->lineEdit_proName->setText("");
        ui->lineEdit_proFilePath->setText(this->proFilePath);
    }
    else
    {
        ui->lineEdit_proFilePath->setText(this->proFilePath + arg1 + "/" + arg1 + ".pro");
    }
}


void proStartup_newPro::on_toolButton_clicked()
{/*
    QString path = QFileDialog::getExistingDirectory(this); // 启动选择文件目录对话框

    if (path.isEmpty())
        return;

    this->proFilePath = path + "/";
    ui->lineEdit_proFilePath->setText(this->proFilePath + this->get_projectNamePath());*/
}
